<!-- 云资源申请详情页面 -->
<template>
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
          <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['office']" :trigger-change="true"/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="系统名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'systemName', validatorRules.systemName]" placeholder="请输入系统名称"></a-input>
            </a-form-item>
          </a-col>
          </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="信息化负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'principal', validatorRules.principal]" placeholder="请输入信息化负责人"></a-input>
            </a-form-item>
          </a-col>
        <!--负责人联系电话-->
          <a-col :span="8">
            <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'principalPhone', validatorRules.principalPhone]" placeholder="请输入负责人联系电话"></a-input>
            </a-form-item>
          </a-col>
        <!--负责人邮箱-->
          <a-col :span="8">
            <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'principalMail', validatorRules.principalMail]" placeholder="请输入负责人邮箱"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'linkman', validatorRules.linkman]" placeholder="请输入联系人"></a-input>
            </a-form-item>
          </a-col>
          <!--联系人联系电话-->
          <a-col :span="8">
            <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'linkmanPhone', validatorRules.linkmanPhone]" placeholder="请输入联系人联系电话"></a-input>
            </a-form-item>
          </a-col>
        <!--联系人邮箱-->
          <a-col :span="8">
            <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'linkmanMail', validatorRules.linkmanMail]" placeholder="请输入联系人邮箱"></a-input>
            </a-form-item>
          </a-col>
        </a-row>

          <a-form-item label="主要用途"
            :labelCol="{lg: {span: 2}, sm: {span: 7}}"
             :wrapperCol="{lg: {span: 14}, sm: {span: 22} }">
            <a-textarea v-decorator="['mainUses']" rows="4" placeholder="请输入主要用途"/>
          </a-form-item>

<!--        <a-row :gutter="24">-->
<!--          <a-col :span="12">-->
            <a-form-item label="服务项目类型"
                         :labelCol="{lg: {span: 2}, sm: {span: 6}}"
                         :wrapperCol="{lg: {span: 14}, sm: {span: 26} }">
              <j-multi-select-tag type="checkbox"  v-decorator="['tos']"  :trigger-change="true" dictCode="tos" placeholder="请选择申请的服务项目类型"/>
            </a-form-item>
<!--          </a-col>-->
<!--        </a-row>-->
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="上传文件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['filePath']" text="上传文件"></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="服务器申请附表" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="jinanGovernmentLedgerAttachedTable.loading"
            :columns="jinanGovernmentLedgerAttachedTable.columns"
            :dataSource="jinanGovernmentLedgerAttachedTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </a-tab-pane>

      </a-tabs>

    </a-spin>
  </a-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import JDate from '@/components/jeecg/JDate'  
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JMultiSelectTag from "@/components/dict/JMultiSelectTag"
  import JUpload from '@/components/jeecg/JUpload'

  export default {
    name: 'JinanGovernmentLedgerMainModal',
    mixins: [JEditableTableMixin],
    components: {
      JDate,
      JSelectDepart,
      JMultiSelectTag,
      JUpload
    },
    data() {
      return {
        labelCol: {
          xs: { span: 22 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 10 },
          sm: { span: 18}
        },
        labelCol2: {
          xs: { span: 12 },
          sm: { span: 4 }
        },
        wrapperCol2: {
          xs: { span: 4 },
          sm: { span: 22 }
        },
        disableSubmit:false,
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
          updateTime:{},
          office:{},
          principal:{},
          principalPhone:{rules: [{validator: this.validatePhone}]},
          principalMail:{rules: [{validator: this.validateEmail}]},
          linkman:{},
          linkmanPhone:{rules: [{validator: this.validatePhone}]},
          linkmanMail:{rules: [{validator: this.validateEmail}]},
          systemName:{},
          mainUses:{},
          tos:{},
        },
        refKeys: ['jinanGovernmentLedgerAttached', ],
        tableKeys:['jinanGovernmentLedgerAttached', ],
        activeKey: 'jinanGovernmentLedgerAttached',
        // 服务器申请附表
        jinanGovernmentLedgerAttachedTable: {
          loading: false,
          dataSource: [],
          options:[],
          columns: [
              {   //此隐藏字段不要删除，主要解决360浏览器 input类型无法读取数据问题
                  title: '服务器名称',
                  key: '',
                  type: FormTypes.hidden,
                  defaultValue: '',
                  placeholder: '请输入${title}',
                  align:"center",
              },
            {
              title: '服务器名称',
              key: 'serverName',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '请输入${title}',
              align:"center",
            },
            // {
            //   title: '数量',
            //   key: 'num',
            //   type: FormTypes.inputNumber,
            //   // defaultValue: '',
            //   placeholder: '请输入${title}',
            //   align:"center",
            // },
            {
              title: 'CPU配置(核)',
              key: 'cpu',
              type: FormTypes.inputNumber,
              defaultValue: '',
              placeholder: '请输入${title}',
              // dictCode:'cpu',
              align:"center",
            },
            {
              title: '内存配置(G)',
              key: 'memory',
              type: FormTypes.inputNumber,
              defaultValue: '',
              placeholder: '请输入${title}',
              // dictCode:'memory',
              align:"center",
            },
            {
              title: '云硬盘配置(G)',
              key: 'disk',
              type: FormTypes.inputNumber,
              defaultValue: '',
              placeholder: '请输入${title}',
              align:"center",
            },
            {
              title: '操作系统类型',
              key: 'os',
              type: FormTypes.select,
              defaultValue: '',
              placeholder: '请输入${title}',
              dictCode:'os',
              align:"center",
            },
            {
              title: '数据库类类型',
              key: 'dataBase',
              type: FormTypes.select,
              defaultValue: '',
              placeholder: '请输入${title}',
              align:"center",
              dictCode:"jinan_data_base,dataBase_name,id"
            },
            {
              title: '互联网IP需求',
              type: FormTypes.select,
              defaultValue: '',
              placeholder: '请输入${title}',
              key: 'outernetIp',
              options: [],
              dictCode: 'outernetIp',
              align:"center",
            },
            {
              title: '备注',
              key: 'rest',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '请输入${title}',
              align:"center",
            },
          ]
        },
        url: {
          fileUpload: window._CONFIG['domianURL']+"/sys/common/upload",
          imgerver: window._CONFIG['domianURL']+"/sys/common/view",
          add: "/jinanServer/jinanGovernmentLedgerMain/add",
          edit: "/jinanServer/jinanGovernmentLedgerMain/edit",
          jinanGovernmentLedgerAttached: {
            list: '/jinanServer/jinanGovernmentLedgerMain/queryJinanGovernmentLedgerAttachedByMainId'
          },
        }
      }
    },
    methods: {
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'updateTime','office','principal','principalPhone','principalMail','linkman','linkmanPhone','linkmanMail','systemName','mainUses','tos','filePath')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.jinanGovernmentLedgerAttached.list, params, this.jinanGovernmentLedgerAttachedTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        debugger
        let main = Object.assign(this.model, allValues.formValue)

        return {
          ...main, // 展开
          jinanGovernmentLedgerAttachedList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
      validateEmail(rule, value, callback){
        if(!value){
          callback()
        }else{
          if(new RegExp(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/).test(value)){
            callback()
          }else{
            callback("请输入正确格式的邮箱!")
          }
        }
      },

        //2020.4.22  14:56  雪糕修改正则表达式检验手机号输入格式（长度）。
        validatePhone(rule, value, callback){
            if(!value){
                callback()
            }else{
                if(new RegExp(/^1[3|4|5|7|8][0-9]\d{8}$/).test(value)){
                    callback()
                }else{
                    callback("请输入正确格式的手机号码!");
                }
            }
        },


    }
  }
</script>

<style scoped>
</style>